import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import CustomerView from '../views/CustomerView.vue'
import OrderView from '../views/OrderView.vue'
import FieldConfigView from '../views/FieldConfigView.vue' // 新增字段配置路由

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    meta: {
      title: '首页 - 动态字段管理系统'
    }
  },
  {
    path: '/customer',
    name: 'customer',
    component: CustomerView,
    meta: {
      title: '客户管理 - 动态字段管理系统'
    }
  },
  {
    path: '/order',
    name: 'order',
    component: OrderView,
    meta: {
      title: '订单管理 - 动态字段管理系统'
    }
  },
  {
    path: '/field-config', // 新增字段配置路由
    name: 'fieldConfig',
    component: FieldConfigView,
    meta: {
      title: '字段配置 - 动态字段管理系统'
    }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫：设置页面标题
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
